from django.db import models


class Cate(models.Model):
    cate_name = models.CharField(max_length=200)

    class Meta:
        db_table = 'cate'

    def __str__(self):
        return self.cate_name


# `goods_goods`(`id`,`name`,`price`,`selling_price`,`image`,`desc`,`stock`,`count`,`cate_id`)
class Goods(models.Model):
    name = models.CharField(max_length=200)
    price = models.DecimalField(max_digits=9, decimal_places=2)
    selling_price = models.DecimalField(max_digits=9, decimal_places=2)
    image = models.CharField(max_length=300)
    desc = models.CharField(max_length=300)
    stock = models.IntegerField()
    count = models.IntegerField()
    cate = models.ForeignKey(to=Cate, on_delete=models.CASCADE)

    class Meta:
        db_table = 'goods'

    def __str__(self):
        return self.name


# `goods_sku`(`id`,`sku_name`,`stock`,`selling_price`,`count`,`goods_id`)
class Sku(models.Model):
    sku_name = models.CharField(max_length=200)
    stock = models.IntegerField()
    selling_price = models.DecimalField(max_digits=9, decimal_places=2)
    count = models.IntegerField()
    goods = models.ForeignKey(to=Goods, on_delete=models.CASCADE)

    class Meta:
        db_table = 'sku'

    def __str__(self):
        return self.sku_name


# `goods_skuimage`(`id`,`path`,`sku_id`)
class Skuimage(models.Model):
    path = models.CharField(max_length=300)
    sku = models.ForeignKey(to=Sku, on_delete=models.CASCADE)

    class Meta:
        db_table = 'skuimage'

    def __str__(self):
        return self.path





